package utils

import (
	"strings"

	"go.mongodb.org/mongo-driver/bson"
)

// 将字段数组转换为选择器
func FieldsArrayToSelector(fields []string) bson.M {
	selector := bson.M{}
	if len(fields) > 0 {
		for _, v := range fields {
			if strings.HasPrefix(v, "-") {
				selector[v[1:]] = 0
				continue
			} else {
				selector[v] = 1
			}
		}
	}
	return selector
}
